<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2025/7/26
  Time: 15:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><!DOCTYPE html>
<!DOCTYPE html>
<html>

<head>
    <base href="/oa1/" />
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="static/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
    <style>
        /*定义类名为.thead-blue的样式*/
        .thead-blue {
            color: #fff;
            font-weight: bold;
            background-color: #337ab7;
        }
    </style>
    <script src="static/jquery/jquery-1.10.2.min.js"></script>
    <script src="static/bootstrap-3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

<!-- 搜索 -->
<div class="panel panel-primary">
    <div class="panel-heading">
        <h4 class="panel-title">所有意向客户</h4>
    </div>
    <div class="panel-body">
        <form action="kh/customer/listKhCustomer" id="seachform" method="post" class="form-horizontal" role="form">
            <div class="form-group">
                <div class="col-md-5">
                    <label for="customerName" class="col-md-4 control-label">客户名称</label>
                    <div class="col-md-8">
                        <!-- 回显客户名称 -->
                        <input type="text" id="customerName" name="customerName" class="form-control"
                               placeholder="请输入客户名称" value="${searchCustomerName}">
                        <input type="hidden" name="page" id="page" value="${pageInfo.current}">
                        <input type="hidden" name="pageSize" id="pageSize" value="${pageInfo.size}">
                    </div>
                </div>
                <div class="col-md-5">
                    <label for="phone" class="col-md-4 control-label">客户电话</label>
                    <div class="col-md-8">
                        <!-- 回显客户电话 -->
                        <input type="text" id="phone" name="phone" class="form-control"
                               placeholder="请输入客户电话" value="${searchPhone}">
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="col-md-12">
                        <!-- 修正添加按钮路径（与控制器映射匹配） -->
                        <a type="button" href="kh/customer/toAddKhCustomer" class="btn btn-info">添加意向客户</a>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-5">
                    <label for="companyType" class="col-md-4 control-label">公司性质</label>
                    <div class="col-md-8">
                        <select name="companyType" class="form-control" id="companyType">
                            <option value="">--公司性质--</option>
                            <!-- 回显公司性质选中状态 -->
                            <option value="1" ${searchCompanyType == '1' ? 'selected' : ''}>国有</option>
                            <option value="2" ${searchCompanyType == '2' ? 'selected' : ''}>外资</option>
                            <option value="3" ${searchCompanyType == '3' ? 'selected' : ''}>合资</option>
                            <option value="4" ${searchCompanyType == '4' ? 'selected' : ''}>私营</option>
                        </select>
                    </div>
                </div>
                <div class="col-md-5">
                    <label for="vocation" class="col-md-4 control-label">所属行业</label>
                    <div class="col-md-8">
                        <select name="vocation" class="form-control" id="vocation">
                            <option value="">--所属行业--</option>
                            <!-- 回显所属行业选中状态 -->
                            <option value="1" ${searchVocation == '1' ? 'selected' : ''}>制造业</option>
                            <option value="2" ${searchVocation == '2' ? 'selected' : ''}>娱乐业</option>
                            <option value="3" ${searchVocation == '3' ? 'selected' : ''}>IT业</option>
                            <option value="4" ${searchVocation == '4' ? 'selected' : ''}>教育</option>
                            <option value="5" ${searchVocation == '5' ? 'selected' : ''}>外贸</option>
                        </select>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="col-md-12">
                        <button type="button" onclick="searchBtn()" class="btn btn-success">搜索意向客户</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<!-- 列表 -->
<div class="panel panel-primary">
    <table class="table table-bordered table-hover">
        <thead>
        <tr class="thead-blue" align="center">
            <td>客户名称</td>
            <td>公司性质</td>
            <td>所属行业</td>
            <td>电话</td>
            <td>传真</td>
            <td>邮箱</td>
            <td>客户关心产品</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        <!-- 遍历分页查询的客户列表 -->
        <c:forEach items="${pageInfo.records}" var="customer">
            <tr align="center">
                <!-- 客户名称（对应实体类customerName属性） -->
                <td>${customer.customerName}</td>
                <!-- 公司性质（将编码转换为文字） -->
                <td>
                    <c:choose>
                        <c:when test="${customer.companyType == '1'}">国有</c:when>
                        <c:when test="${customer.companyType == '2'}">外资</c:when>
                        <c:when test="${customer.companyType == '3'}">合资</c:when>
                        <c:when test="${customer.companyType == '4'}">私营</c:when>
                        <c:otherwise>--</c:otherwise>
                    </c:choose>
                </td>
                <!-- 所属行业（将编码转换为文字） -->
                <td>
                    <c:choose>
                        <c:when test="${customer.vocation == '1'}">制造业</c:when>
                        <c:when test="${customer.vocation == '2'}">娱乐业</c:when>
                        <c:when test="${customer.vocation == '3'}">IT业</c:when>
                        <c:when test="${customer.vocation == '4'}">教育</c:when>
                        <c:when test="${customer.vocation == '5'}">外贸</c:when>
                        <c:otherwise>--</c:otherwise>
                    </c:choose>
                </td>
                <td>${customer.phone}</td>
                <td>${customer.fax == null ? '' : customer.fax}</td>
                <td>${customer.email == null ? '' : customer.email}</td>
                <td>
                    <a type="button" href="favorite/listKhCustomerfavorite?customerid=${customer.oid}"
                       class="btn btn-success btn-xs">关心的产品</a>
                </td>
                <td>
                    <a type="button" href="kh/customer/khCustomerInfo?oid=${customer.oid}"
                       class="btn btn-info btn-xs">详情</a>
                    <a type="button" href="kh/customer/toUpdateKhCustomer?oid=${customer.oid}"
                       class="btn btn-primary btn-xs">修改</a>
                    <button type="button" onclick="deleteKhCustomer(${customer.oid})"
                            class="btn btn-danger btn-xs" data-toggle="modal" data-target="#confirmModal">删除</button>
                </td>
            </tr>
        </c:forEach>

        <!-- 无数据时显示 -->
        <c:if test="${pageInfo.total == 0}">
            <tr align="center">
                <td colspan="8">暂无意向客户数据</td>
            </tr>
        </c:if>
        </tbody>
    </table>
</div>

<br><br><br>

<!-- 模态框（Modal） -->
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="confirmModalLabel">
                    提示
                </h4>
            </div>
            <div class="modal-body">
                确认删除吗？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" id="subconfirm" class="btn btn-primary">
                    提交更改
                </button>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
        $("#subconfirm").click(function(){
            deleteConfirm();
            $('#confirmModal').modal('hide');
        });
    });
</script>


<!-- 模态框（Modal） -->
<div class="modal fade" id="alertMsgModal" tabindex="-1" role="dialog" aria-labelledby="alertMsgModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xs">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="alertMsgModalLabel">
                    提示
                </h4>
            </div>
            <div class="modal-body" id="alertmsg">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(document).ajaxError(function(event,xhr) {
        if(xhr.status=="403"){//没有权限
            document.location.href = xhr.getResponseHeader("url");
        }else if(xhr.status!="200"){
            //alert("服务器错误!");
            console.log("服务器错误!");
        }
    });
</script>


</body>
<script type="text/javascript">
    function gotoPage(page, pageSize){
        $("#page").val(page);
        $("#pageSize").val(pageSize);
        $("#seachform").submit(); // 表单action已修正，无需额外修改
    }
    function searchBtn(){
        $("#page").val(1);
        $("#seachform").submit();
    }

    var deleteoid;
    function deleteKhCustomer(oid){
        deleteoid = oid;
    }
    function deleteConfirm(){
        // 修正删除请求路径
        $.get("kh/customer/deleteKhCustomer", {"oid":deleteoid}, function(s){
            if(s == true){
                // 修正刷新路径
                document.location.href = "kh/customer/listKhCustomer";
            }else{
                $("#alertmsg").text("删除失败!当前客户有联系人或关心的产品!");
                $('#alertMsgModal').modal('show');
            }
        });
    }
</script>
</html>
